require 'mu_api'
require 'erb'

# Run an existing template with some elements changed
# This script uses ruby templating with the ERB class

# The template should be a normal mu template
# marked up with templating tags:
#
# <%= Ruby expression -- replace with result %>

# For more information;
# http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html
# 
# Read original with templating tags. In this case, the template contains:

# Set template values
@name = "Sample 1"
@host_1 = "a1"
@type_1 = "IF_V4"
@host_2 = "dell-eth1"
@type_2 = "HOST_V4"

$DEBUG = true

# Read in template and apply new values
original = File.read("sample.xml")
sample = ERB.new(original)
template = sample.result
puts template

# Template now has new values that we can post and run
api = Mu_Api.new(ENV['MU_IP'])
api.post(template)
api.run

# Run against another host
@name = "Sample 2"
@host_2 = "dell-10"
sample2 = ERB.new(original)
template2 = sample2.result
api.post(template2)
api.run


